import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        File f = new File("test.txt");
        if (f.exists()){
            System.out.println("文件存在");
        }else {
            System.out.println("文件不存在");
            try {
                f.createNewFile();
            }catch (IOException e){
                System.out.println("创建文件异常");
                e.printStackTrace();
            }
            System.out.println(f.canRead());
            System.out.println(f.canWrite());
        }
        File f2 = new File("E:\\java-program\\Ex10_1\\src","Main.java");
        System.out.println(f2.getAbsolutePath());
        if (f2.exists()){
            System.out.println("Main.java存在");
            System.out.println("文件是否可读"+f2.canRead());
            System.out.println("文件是否可写"+f2.canWrite());
            System.out.println("文件是否具有执行权限"+f2.canExecute());
            System.out.println("文件名称"+f2.getName());
            System.out.println("文件父路径"+f2.getParent());
            System.out.println("文件获取路径"+f2.getPath());
            System.out.println("文件长度"+f2.length());
        }else {
            System.out.println("Main.java不存在");
        }
        File f3 = new File("DIR");
        if (f3.mkdir()){
            System.out.println("目录创建成功");
        }else {
            System.out.println("目录创建失败");
        }
        String[] filenames = f3.list();
        System.out.println("目录文件名：↓");
        if (filenames != null){
            for(String item : filenames){
                System.out.println(item);
            }
        }
        FileFilter filter = new FileFilter();
        String[] filterFileNames = f3.list(filter);
        System.out.println("过滤后的目录文件名：↓");
        if (filterFileNames != null){
            for(String item : filterFileNames){
                System.out.println(item);
            }
        }
    }
}